﻿Public Class Create_new_Recipient

    Private Sub RecipientsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecipientsBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.RecipientsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.OurDataBaseDataSet)

    End Sub

    Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'OurDataBaseDataSet.Groups' table. You can move, or remove it, as needed.
        Me.GroupsTableAdapter.Fill(Me.OurDataBaseDataSet.Groups)
        'TODO: This line of code loads data into the 'OurDataBaseDataSet.Recipients' table. You can move, or remove it, as needed.
        Me.RecipientsTableAdapter.Fill(Me.OurDataBaseDataSet.Recipients)



        GroupNameComboBox.Enabled = False
        E_mailTextBox.Enabled = False
        CityTextBox.Enabled = False
        FirstNameTextBox.Enabled = False
        LastNameTextBox.Enabled = False
        CityTextBox.Enabled = False
        AddDateDateTimePicker.Enabled = False
        IdRTextBox.Enabled = False

    End Sub

    Private Sub Create_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Create.Click

        If GroupNameComboBox.Enabled = False Then
            MessageBox.Show("Add New ", "Error text field")
        End If

        If GroupNameComboBox.Enabled = True And GroupNameComboBox.Text <> "" And E_mailTextBox.Text <> "" And CityTextBox.Text <> "" And FirstNameTextBox.Text <> "" And LastNameTextBox.Text <> "" And CityTextBox.Text <> "" Then
            Dim dr As DataRow = Me.OurDataBaseDataSet.Recipients.NewRow()



            '8etw times sta pedia 
            dr.Item(0) = IdRTextBox.Text
            dr.Item(1) = GroupNameComboBox.Text
            dr.Item(2) = E_mailTextBox.Text
            dr.Item(3) = FirstNameTextBox.Text
            dr.Item(4) = LastNameTextBox.Text
            dr.Item(5) = CityTextBox.Text
            dr.Item(6) = AddDateDateTimePicker.Text


            'pros8hkh grammhs ston pinaka
            Me.OurDataBaseDataSet.Recipients.Rows.Add(dr)


            Me.Validate()
            Me.RecipientsBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.OurDataBaseDataSet)


            'emfanish mhnumatos epituxous eisagwghs
            MessageBox.Show("Saved", "Insert new row")
        Else
            MessageBox.Show(" Not Saved. Fill in all fields ", "Insert Failed")
        End If
    End Sub

    Private Sub Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Remove.Click
        Me.RecipientsBindingSource.RemoveCurrent()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.RecipientsBindingSource.RemoveCurrent()


    End Sub



    Private Sub add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add.Click
        Me.RecipientsBindingSource.AddNew()

        GroupNameComboBox.Enabled = True
        E_mailTextBox.Enabled = True
        CityTextBox.Enabled = True
        FirstNameTextBox.Enabled = True
        LastNameTextBox.Enabled = True
        CityTextBox.Enabled = True
        AddDateDateTimePicker.Enabled = True
        IdRTextBox.Enabled = True
    End Sub

   
End Class